package com.wty.love.loveTalk;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.wty.love.R;

import java.util.HashSet;
import java.util.Random;

public class LoveTalkActivity extends AppCompatActivity {
    private TextView about;
    private View refresh;
    private EditText content;
    private String[] values;//存储所有短句的数组
    private HashSet<Integer> set;//存储已经随机生成过的坐标
    private Random random = new Random();
    private int clickNum = 1;//刷新按钮点击次数

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_love_talk);
        initView();
        initData();
        initClick();
    }

    private void initClick() {
        refresh.setOnClickListener(v->{
            content.setText( getRandomStr(values.length) );
            clickNum++;
            if (clickNum%5==0&&clickNum%2==0){
                about.setText("爱你呀");
            }else {
                about.setText("关于");
            }
        });
        about.setOnClickListener(v->{
            if (clickNum%5==0&&clickNum%2==0){//其实直接对10取余就可，但是我觉得这样比较浪漫
                //情书
                AboutAndLoveTalkActivity.flag = 1;
            }else {
                //关于
                AboutAndLoveTalkActivity.flag = 0;
            }
            Intent intent = new Intent(this,AboutAndLoveTalkActivity.class);
            startActivity(intent);
        });
    }

    private void initView() {
        content = findViewById(R.id.content);
        refresh = findViewById(R.id.refresh);
        about = findViewById(R.id.about);
    }

    private void initData() {
        String value = getResources().getString(R.string.loveTalk);
        values = value.split("#");
        set = new HashSet<>(values.length);
        content.setText( getRandomStr(values.length) );
    }

    private String getRandomStr(int num){
        int number = 0;
        if (num<=0) return "(●'◡'●)\n";
        if (num==set.size()){
            set = new HashSet<>();
            return "我最爱最爱最爱最爱你啦(✿◡‿◡)\n";
        }
        number = random.nextInt(num);
        while (set.contains(number)){
            number = random.nextInt(num);
        }
        set.add(number);
        return values[number];
    }
}